<template>
  <div>
    <div class="header">
      <p>{{ goodsLists.product_name }}</p>
      <ul>
        <li>
          <a href="JavaScript:;" class="router-link-active">概述</a>
        </li>
        <li>
          <a href="JavaScript:;" class="router-link-active">参数</a>
        </li>
        <li>
          <a href="JavaScript:;" class="router-link-active">用户评价</a>
        </li>
      </ul>
    </div>
    <div class="main">
      <el-carousel height="560px">
        <el-carousel-item v-for="item in getDetailsList" :key="item.id">
          <img :src="$target + item.product_picture" alt />
        </el-carousel-item>
      </el-carousel>

      <div class="mains">
        <h1>{{ goodsLists.product_name }}</h1>
        <p class="p1">{{ goodsLists.product_intro }}</p>
        <p class="p2">小米自营</p>
        <div class="prices">
          <span>{{ goodsLists.product_selling_price }}元</span>
          <span
            class="del"
            v-if="goodsLists.product_price !== goodsLists.product_selling_price"
            >{{ goodsLists.product_price }}元</span
          >
        </div>
        <div class="jiaru">
          <div class="pro-list">
            <span class="pro-name">Redmi K20/ K20 Pro 怪力魔王保护壳</span>
            <span class="pro-price">
              <span>{{ goodsLists.product_selling_price }}元</span>
              <span class="pro-del" style="display: none"
                >{{ goodsLists.product_selling_price }}元</span
              >
            </span>
            <p class="price-sum">
              总计 : {{ goodsLists.product_selling_price }}元
            </p>
          </div>
        </div>
        <div class="button">
          <button
            @click="cartAdd"
            type="button"
            class="el-button shop-cart el-button--default"
          >
            <span>加入购物车</span>
          </button>
          <el-button
            @click="love"
            type="button"
            class="el-button like el-button--default"
          >
            <span>喜欢</span>
          </el-button>
        </div>
        <div class="pro-policy">
          <ul>
            <li><i class="el-icon-circle-check"></i> 小米自营</li>
            <li><i class="el-icon-circle-check"></i> 小米发货</li>
            <li><i class="el-icon-circle-check"></i> 7天无理由退货</li>
            <li><i class="el-icon-circle-check"></i> 7天价格保护</li>
          </ul>
        </div>
        <Login  :booleans="panduan" @bools="bools"></Login>
      </div>
    </div>
  </div>
</template>

<script>
import API from "../../API/Api";
export default {
  name: "",
  data() {
    return {
      goodsLists: {},
      getDetailsList: [],
      product_id: 0,
      panduan: false,
    };
  },
  mounted() {
    var id = this.$route.query.productID;
    this.product_id = id;
    API.goodsLists(id).then((res) => {
      // console.log(res);
      this.goodsLists = res.Product[0];
    });
    API.getDetails(id).then((res) => {
      this.getDetailsList = res.ProductPicture;
      // console.log(this.getDetailsList);
    });

    API.getCollect({ user_id: this.$store.state.user_id }).then((res) => {
      console.log(res);
    });
  },
  methods: {
    love() {
      if (this.$store.state.trueFalse) {
        console.log({
          product_id: this.product_id,
          user_id: this.$store.state.user_id,
        });
        // API.goodsLists(this.product_id).then((res) => {
        //   console.log(res);
        //   this.goodsLists = res.Product[0];
        // });

        API.loves({
          "product_id": this.product_id,
          "user_id": this.$store.state.user_id,
        }).then(res => {
          console.log(res);
        });
      } else {
        this.panduan = true;
        console.log(this.$store.state.trueFalse);
      }
    },
    bools() {
      this.panduan = false;
    },
    cartAdd() {
      if (this.$store.state.trueFalse) {
        console.log({
          product_id: this.product_id,
          user_id: this.$store.state.user_id,
        });
        API.addShoppingCart({
          user_id: this.$store.state.user_id,
          product_id: this.product_id,
        }).then((res) => {
          console.log(res);
        });
      } else {
        this.panduan = true;
        console.log(this.$store.state.trueFalse);
      }
    },
  },
  computed: {},
  components: {},
  watch: {},
  getters: {},
};
</script>

<style scoped>
.header {
  width: 1225px;
  height: 64px;
  line-height: 64px;
  font-size: 18px;
  font-weight: 400;
  color: #212121;
  margin: 0 auto;
}
.header p {
  float: left;
}
.header ul {
  height: 64px;
  float: right;
}
.header li {
  list-style: none;
  float: left;
  margin-left: 20px;
}
.router-link-active {
  text-decoration: none;
  font-size: 14px;
  color: #616161;
}
.main {
  width: 1225px;
  height: 560px;
  padding-top: 30px;
  margin: 0 auto;
}
.main img {
  float: left;
  width: 560px;
  width: 560px;
}
.mains {
  float: left;
  margin-left: 25px;
  width: 640px;
  height: 100%;
}
.mains h1 {
  height: 30px;
  line-height: 30px;
  font-size: 24px;
  font-weight: 400;
  color: #212121;
}
.p1 {
  color: #b0b0b0;
  padding-top: 10px;
}
.p2 {
  color: #ff6700;
  padding-top: 10px;
}
.prices {
  display: block;
  font-size: 18px;
  color: #ff6700;
  border-bottom: 1px solid #e0e0e0;
  padding: 25px 0 25px;
}
.del {
  font-size: 14px;
  margin-left: 10px;
  color: #b0b0b0;
  text-decoration: line-through;
}
.jiaru {
  background: #f9f9fa;
  padding: 30px 60px;
  margin: 50px 0 50px;
}
.pro-price {
  line-height: 30px;
  color: #616161;
}
.pro-price span {
  float: right;
}
.price-sum {
  color: #ff6700;
  font-size: 24px;
  padding-top: 20px;
}
.el-button {
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}
.shop-cart {
  width: 340px;
  background-color: #ff6700;
}
.button .like {
  width: 260px;
  margin-left: 40px;
  background-color: #b0b0b0;
}
.button .el-button {
  float: left;
  height: 55px;
  font-size: 16px;
  color: #fff;
  border: none;
  text-align: center;
}
.pro-policy li {
  list-style: none;
  float: left;
  margin-right: 20px;
  color: #b0b0b0;
  margin-top: 20px;
}
.el-carousel {
  width: 560px;
  float: left;
}
.el-carousel__item img {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #688cbe;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>